"use server";
import "./index.css";
import Title from "antd/es/typography/Title";
import { Divider, Flex, message } from "antd";
import Link from "next/link";
import { userLoginUsingPost } from "@/api/userController";
import { setLoginUser } from "@/stores/loginUser";
import { listQuestionBankVoByPageUsingPost } from "@/api/questionBankController";
import {listQuestionVoByPageUsingPost, searchQuestionVoByPageUsingPost} from "@/api/questionController";
import QuestionBankList from "@/components/QuestionBankList";
import React from "react";
import QuestionList from "@/components/QuestionList";
import QuestionTable from "@/components/QuestionTable";

/**
 * 题目列表页面
 * @constructor
 */

export default async function QuestionsPage({ searchParams }) {
  //获取url的查询参数
  const { q: searchText } = searchParams;
  //题目列表和总数
  let questionList = [];
  let total = 0;

  try {
    const res = await searchQuestionVoByPageUsingPost({
      searchText,
      pageSize: 12,
      sortField: "createTime",
      sortOrder: "desc",
    });
    questionList = res.data.records ?? [];
    total = res.data.total ?? 0;
  } catch (e) {
    message.error("获取题目列表失败，" + (e as Error).message);
  }

  return (
    <div id="questionPage" className="max-width-content">
      <Title level={3}>题目大全</Title>
      <QuestionTable
        deafaultQuestionList={questionList}
        defaultTotal={total}
        defaultSearchParams={{
          title: searchText,
        }}
      />
    </div>
  );
}
